package com.demo2do.fms.admin.entity.search.report;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.supplier.common.Type;
import com.demo2do.fms.entity.vehicle.AuditStatus;

/**
 *
 * @author Ark
 *
 */
public class TransportToolSearch implements QueryBuilder {

    // =========== 供方用 ==========
    /** 供方代码 */
    private String code;
    
    /** 供方名称 */
    private String name;
    
    // =========== 车辆用 ============
    /** 车辆状态 */
    private AuditStatus status;
    
    /** 是否同步 */
    private Boolean synchronize;
    
    private QueryFilter queryFilter;

    private QueryOrder queryOrder;
    
    /**
     * The default constructor
     */
    public TransportToolSearch() {
        queryOrder = new QueryOrder();
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if (queryFilter == null || refresh) {
            
            queryFilter = new QueryFilter().addEquals("code", code)
                                           .addLike("name", name)
                                           .addEquals("type", Type.MOTOR);
            
        }
        
        return queryFilter;
        
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM Supplier WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + queryOrder.sentence();
        return sentence;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return
     */
    public AuditStatus getStatus() {
        return status;
    }

    /**
     * @return the synchronize
     */
    public Boolean getSynchronize() {
        return synchronize;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param status
     */
    public void setStatus(AuditStatus status) {
        this.status = status;
    }

    /**
     * @param synchronize the synchronize to set
     */
    public void setSynchronize(Boolean synchronize) {
        this.synchronize = synchronize;
    }
    
}
